package cn.orange;

public class ListNode {
    public int val;
    public ListNode next;

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        ListNode curr = this;
        while (curr != null) {
            if (curr.next != null) {
                sb.append(curr.val).append("->");
            } else {
                sb.append(curr.val);
            }
            curr = curr.next;
        }
        sb.append("]");
        return sb.toString();
    }
}
